/*
 ID: brodyzt
 PROG: namenum
 LANG: C++
 */

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <math.h>
#include <stdlib.h>
#include <vector>

using namespace std;



int intLength (double num)
{
    stringstream tempStream;
    tempStream << num;
    string tempString;
    tempStream >> tempString;
    return (int)tempString.length();
}

string intToString (double num)
{
    stringstream tempStream;
    tempStream.precision(30);
    tempStream << num;
    string tempString;
    tempStream >> tempString;
    return tempString;
}

int numDigitMostCommon (int num)
{
    string tempString = intToString(num);
    vector<int> digits (10, 0);
    for (int i = 0; i < tempString.length(); i++) {
        digits[(int)tempString[i] - 48] ++;
    }
    int max = 0;
    for (int i = 0; i < digits.size(); i++) {
        if (digits[i] > max) {
            max = digits[i];
        }
    }
    return max;
}

int letterToNum (char letter)
{
    int num = 0;
    char decoder[8][3] = {
        {'A','B','C'},
        {'D','E','F'},
        {'G','H','I'},
        {'J','K','L'},
        {'M','N','O'},
        {'P','R','S'},
        {'T','U','V'},
        {'W','X','Y'}
    };
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 3; j++) {
            if (letter == decoder[i][j]) {
                num = i + 2;
            }
        }
    }
    return num;
}

double nameToNum (string name)
{
    stringstream tempStream;
    tempStream.precision(50);
    for (int i = 0; i < name.length(); i++) {
        tempStream << letterToNum(name[i]);
    }
    double num;
    tempStream >> num;
    return num;
}

int swappedDigitsInNumber (int num, int index1, int index2)
{
    string tempString = intToString(num);
    char tempChar = tempString[index1];
    tempString[index1] = tempString[index2];
    tempString[index2] = tempChar;
    stringstream tempStream;
    tempStream.precision(30);
    tempStream << tempString;
    int tempNum;
    tempStream >> tempNum;
    return tempNum;
}

string swappedLettersInWord (string word, int index1, int index2)
{
    char tempChar = word[index1];
    word[index1] = word[index2];
    word[index2] = tempChar;
    return word;
}

vector<int> swappedIndexesInVector (vector<int> array, int index1, int index2)
{
    int tempInt = array[index1];
    array[index1] = array[index2];
    array[index2] = tempInt;
    return array;
}

bool intIsInVector (int num, vector<int> array)
{
    for (int i = 0; i < array.size(); i++) {
        if (num == array[i]) {
            return true;
        }
    }
    return false;
}

bool stringIsInVector (string tempString, vector<string> array)
{
    for (int i = 0; i < array.size(); i++) {
        if (tempString == array[i]) {
            return true;
        }
    }
    return false;
}

int factorial (int num)
{
    if (num == 1 || num == 0) {
        return 1;
    } else {
        return num * factorial(num - 1);
    }
}

bool vectorIsInOrder (vector<int> array)
{
    for (int i = 0; i < array.size() - 1; i++) {
        if(array[i] > array [i+1])
        {
            return false;
        }
    }
    return true;
}

vector<int> bubbleSorted (vector<int> array)
{
    while (!vectorIsInOrder(array)) {
        for (int i = 0; i < array.size() - 1; i++) {
            if (array[i] > array[i+1]) {
                array = swappedIndexesInVector(array, i, i+1);
            }
        }
    }
    return array;
}

string randomNameUsingNum (double num)
{
    char decoder[8][3] = {
        {'A','B','C'},
        {'D','E','F'},
        {'G','H','I'},
        {'J','K','L'},
        {'M','N','O'},
        {'P','R','S'},
        {'T','U','V'},
        {'W','X','Y'}
    };
    stringstream tempStream;
    vector<int> randomValues;
    for (int i = 0; i < intLength(num); i++) {
        tempStream << decoder[(int)intToString(num)[i] - 50][rand() % 3];
    }
    string tempString;
    tempStream >> tempString;
    return tempString;
}

vector<string> calcPosibleNameCombos (double num)
{
    vector<string> possibleCombos;
    vector<int> randomDigits;
   int length = 0;
    while (length < pow(3, intLength(num))) {
        string tempString = randomNameUsingNum(num);
        if (!stringIsInVector(tempString, possibleCombos)) {
            length++;
            possibleCombos.push_back(tempString);
            cout << tempString;
        }
    }
    return possibleCombos;
}

int main(int argc, const char * argv[])
{
    ifstream dictionary("dict.txt"), input("namenum.in");
    input.precision(30);
    dictionary.precision(30);
    cout.precision(30);
    double origNum;
    input >> origNum;
    cout << origNum;
    ofstream output("namenum.out");
    output.precision(30);
    int counter = 0;
    for (int i = 0; i < 4617; i++) {
        string tempString;
        dictionary >> tempString;
        double tempNum = nameToNum(tempString);
        if(tempNum == origNum)
        {
            cout << tempNum << " " << origNum << "\n";
            output << tempString << "\n";
            counter ++;
        }
    }
    if (counter == 0) {
        output << "NONE" << "\n";
    }
    dictionary.close();
    input.close();
    output.close();
    return 0;
}

